package com.cskaoyan.service;

import com.cskaoyan.bean.AfterSale;
import com.cskaoyan.bean.AfterSaleExample;
import com.cskaoyan.bean.BaseParam;
import com.cskaoyan.bean.zhao_order_bean.BasePageData;
import com.cskaoyan.bean.zhao_order_bean.OrderExample;
import com.cskaoyan.mapper.AfterSaleMapper;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <h3>market</h3>
 *
 * @author:Zhao
 * @date:2021-10-19 21:23:41
 * @description:
 */
@Service
public class AfterSaleServiceImpl implements AfterSaleService {
    @Autowired
    AfterSaleMapper afterSaleMapper;

    @Override
    public BasePageData query(String afterSaleSn, Integer orderId, Short status, BaseParam param) {
        //配置分页信息 → 在执行预编译过程，会帮你拼接分页的sql语句
        PageHelper.startPage(param.getPage(), param.getLimit());

        AfterSaleExample example = new AfterSaleExample();
        AfterSaleExample.Criteria criteria = example.createCriteria();
        if (afterSaleSn != null && !"".equals(afterSaleSn)) {
            criteria.andAftersaleSnEqualTo(afterSaleSn);
        }
        if (orderId != null && !"".equals(orderId)) {
            criteria.andOrderIdEqualTo(orderId);
        }
        if (status != null && !"".equals(status)) {
            criteria.andStatusEqualTo(status);
        }

        criteria.andDeletedEqualTo(false);

        example.setOrderByClause(param.getSort() + " " + param.getOrder());

        List<AfterSale> afterSales = afterSaleMapper.selectByExample(example);

        return BasePageData.ok(afterSales);
    }

    @Override
    public void refund(Integer orderId) {
        afterSaleMapper.refund(orderId);
    }

    @Override
    public void recept(Integer orderId) {
        afterSaleMapper.recept(orderId);
    }

    @Override
    public void reject(Integer orderId) {
        afterSaleMapper.reject(orderId);
    }

    @Override
    public void batchRecept(List<Integer> ids) {
        afterSaleMapper.batchRecept(ids);


    }

    @Override
    public void batchReject(List<Integer> ids) {
        afterSaleMapper.batchReject(ids);
    }
}
